<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        li {
            list-style: none;
            line-height: 40px;
            border: 1px dashed #333;
        }

        .list {
            margin-top: 20px;
        }
    </style>
</head>

<body>
    <div class="wrap">
        <button class="editEle">修改元素</button>
        <ul class="list">
            <li class="first">01</li>
            <li>02</li>
            <li class="mid">03</li>
            <li>04</li>
            <li>05</li>
            <li class="last">06</li>
        </ul>
    </div>

</body>
<script>
    var ul = document.querySelector(".list");
    var mid = document.querySelector(".mid");
    var editEle = document.querySelector(".editEle");

    // 节点的修改/替换 

    // parentNode.replaceChild(newNode,oldNode)   => 父节点统筹




    // 点击按钮 => 用一个新的li替换mid
    editEle.onclick = function () {
        console.log(mid);

        if (mid) {
            var li = document.createElement("li");
            li.className = "newLi";
            li.title = "hello";
            li.textContent = "我是新增的li";

            ul.replaceChild(li, mid);
            mid = null;
        }

    }







</script>

</html>